@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion

echo ========================================
echo    五子棋后端 - 日志功能测试脚本
echo ========================================
echo.

:: 检查服务是否启动
curl -s http://localhost:8080/health >nul 2>&1
if !errorlevel! neq 0 (
    echo [错误] 服务未启动，请先启动项目！
    echo 请运行：启动项目.bat
    pause
    exit /b 1
)

echo [提示] 服务已启动，开始测试日志功能...
echo.

:menu
echo ========================================
echo    选择测试项目：
echo ========================================
echo 1. 测试所有日志级别 (TRACE/DEBUG/INFO/WARN/ERROR)
echo 2. 测试带参数的日志输出
echo 3. 测试异常日志记录
echo 4. 测试条件日志
echo 5. 测试业务流程日志
echo 6. 测试批量处理日志优化
echo 7. 测试性能日志
echo 8. 运行所有测试
echo 0. 退出
echo ========================================
echo.

set /p choice="请输入选项 (0-8): "

if "%choice%"=="1" goto test1
if "%choice%"=="2" goto test2
if "%choice%"=="3" goto test3
if "%choice%"=="4" goto test4
if "%choice%"=="5" goto test5
if "%choice%"=="6" goto test6
if "%choice%"=="7" goto test7
if "%choice%"=="8" goto testall
if "%choice%"=="0" goto end

echo [错误] 无效选项，请重新选择！
echo.
goto menu

:test1
echo.
echo [测试1] 所有日志级别
echo ========================================
curl -s http://localhost:8080/log-demo/all-levels
echo.
echo ----------------------------------------
echo [提示] 请查看控制台，应该看到不同颜色的日志输出：
echo   - DEBUG（青色）
echo   - INFO（绿色）
echo   - WARN（黄色）
echo   - ERROR（红色）
echo ========================================
echo.
pause
goto menu

:test2
echo.
echo [测试2] 带参数的日志输出
echo ========================================
curl -s "http://localhost:8080/log-demo/with-params?username=李四&age=30"
echo.
echo ----------------------------------------
echo [提示] 请查看控制台，应该看到带参数的日志输出
echo ========================================
echo.
pause
goto menu

:test3
echo.
echo [测试3] 异常日志记录
echo ========================================
curl -s "http://localhost:8080/log-demo/with-exception?trigger=true"
echo.
echo ----------------------------------------
echo [提示] 请查看控制台，应该看到完整的异常堆栈信息
echo ========================================
echo.
pause
goto menu

:test4
echo.
echo [测试4] 条件日志
echo ========================================
curl -s http://localhost:8080/log-demo/conditional
echo.
echo ----------------------------------------
echo [提示] 请查看控制台，应该看到根据日志级别条件输出的日志
echo ========================================
echo.
pause
goto menu

:test5
echo.
echo [测试5] 业务流程日志
echo ========================================
curl -s -X POST http://localhost:8080/log-demo/business-flow -H "Content-Type: application/json" -d "{\"product\":\"五子棋\",\"quantity\":1}"
echo.
echo ----------------------------------------
echo [提示] 请查看控制台，应该看到完整的业务流程日志
echo   包括：开始、步骤1、步骤2、步骤3、结束
echo ========================================
echo.
pause
goto menu

:test6
echo.
echo [测试6] 批量处理日志优化
echo ========================================
curl -s "http://localhost:8080/log-demo/batch-process?count=100"
echo.
echo ----------------------------------------
echo [提示] 请查看控制台，应该看到汇总日志而非每条数据的日志
echo ========================================
echo.
pause
goto menu

:test7
echo.
echo [测试7] 性能日志
echo ========================================
curl -s http://localhost:8080/log-demo/performance
echo.
echo ----------------------------------------
echo [提示] 请查看控制台，应该看到处理耗时的日志
echo ========================================
echo.
pause
goto menu

:testall
echo.
echo [运行所有测试]
echo ========================================
echo.

echo [1/7] 测试所有日志级别...
curl -s http://localhost:8080/log-demo/all-levels >nul
echo 完成！
timeout /t 1 >nul

echo [2/7] 测试带参数的日志...
curl -s "http://localhost:8080/log-demo/with-params?username=王五&age=28" >nul
echo 完成！
timeout /t 1 >nul

echo [3/7] 测试异常日志...
curl -s "http://localhost:8080/log-demo/with-exception?trigger=true" >nul
echo 完成！
timeout /t 1 >nul

echo [4/7] 测试条件日志...
curl -s http://localhost:8080/log-demo/conditional >nul
echo 完成！
timeout /t 1 >nul

echo [5/7] 测试业务流程日志...
curl -s -X POST http://localhost:8080/log-demo/business-flow -H "Content-Type: application/json" -d "{\"test\":\"data\"}" >nul
echo 完成！
timeout /t 1 >nul

echo [6/7] 测试批量处理日志...
curl -s "http://localhost:8080/log-demo/batch-process?count=50" >nul
echo 完成！
timeout /t 1 >nul

echo [7/7] 测试性能日志...
curl -s http://localhost:8080/log-demo/performance >nul
echo 完成！

echo.
echo ========================================
echo [完成] 所有测试已完成！
echo [提示] 请查看控制台，应该看到所有类型的日志输出
echo ========================================
echo.
pause
goto menu

:end
echo.
echo 感谢使用！再见！
echo.
pause
exit /b 0

